package com.example.administrator.shzs.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.administrator.shzs.R;
import com.example.administrator.shzs.entity.mSoRecycleview;

import java.util.List;

/**
 * 搜索页面adapter
 */
public class SearchRecycleviewAdapter extends RecyclerView.Adapter<SearchRecycleviewAdapter.Item> {

    private List<mSoRecycleview> datalist;
    private Context context;


    public SearchRecycleviewAdapter(List<mSoRecycleview> datalist, Context context) {
        this.datalist = datalist;
        this.context = context;
    }

    private SoSoItem soSoItem;

    public interface SoSoItem {
        void Onclick(View view, int postion);
    }

    public void setSoSoItem(SoSoItem listent) {
        this.soSoItem = listent;
    }

    @Override
    public Item onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.activity_category_item_item, null);

        Item item = new Item(view);

        return item;
    }

    @Override
    public void onBindViewHolder(final Item holder, final int position) {
        holder.textView.setText(datalist.get(position).getSortName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                soSoItem.Onclick(holder.itemView,position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datalist == null ? 0 : datalist.size();
    }

    class Item extends RecyclerView.ViewHolder {
        private TextView textView;

        public Item(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.so_item_item_text);
        }
    }
}
